
package org.amitycs.collabdrawing;

import java.awt.Shape;
import java.util.ArrayList;

/**
 *
 * @author joe
 */
public class Whiteboard {
    private ArrayList<Shape> shapes;
    private ArrayList<WhiteboardListener> listeners;

    public Whiteboard()
    {
        shapes = new ArrayList<Shape>();
        listeners = new ArrayList<WhiteboardListener>();
    }

    private void fireShapeAdded()
    {
        for (WhiteboardListener wl : listeners)
        {
            wl.shapeAdded();
        }
    }

    public void addShape(Shape s)
    {
        synchronized (shapes) {
            shapes.add(s);
        }
        fireShapeAdded();
    }

    public void registerListener(WhiteboardListener wl)
    {
        listeners.add(wl);
    }

    public void removeListener(WhiteboardListener wl)
    {
        listeners.remove(wl);
    }

    public synchronized ArrayList<Shape> getShapes()
    {
        return shapes;
    }
}
